/**
* 项目管理/需求管理
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>需求管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-select size="small" v-model="formInline.taskDTO.taskType" placeholder="类型">
          <el-option value="任务" label="任务"></el-option>
          <el-option value="缺陷" label="缺陷"></el-option>
          <el-option value="需求" label="需求"></el-option>
        </el-select>
        <el-select size="small" v-model="formInline.taskDTO.taskStatus" placeholder="状态">
          <el-option value="创建" label="创建"></el-option>
          <el-option value="进行中" label="进行中"></el-option>
          <el-option value="完成" label="完成"></el-option>
          <el-option value="废弃" label="废弃"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-button @click="handelAdd()">添加任务</el-button>
        <el-button @click="getdata()">搜索</el-button>

      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable prop="id" label="id" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="taskName" label="任务名称" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="taskType" label="任务类型" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="taskStatus" label="任务状态" width="120"
                       show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="taskOwnerAccount" label="任务所属人" width="120"
                       show-overflow-tooltip></el-table-column>

      <el-table-column sortable prop="creatorName" label="任务创建者" width="120"
                       show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="orgName" label="所属组织" width="120"
                       show-overflow-tooltip></el-table-column>
      <el-table-column sortable prop="projectName" label="所属项目" width="120"
                       show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 新增编辑 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="80%" @click="closeDialog('editForm')">
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-row>
          <el-col>
            <el-form-item v-show="false" label="id">
              <el-input size="small" v-model="editForm.id" auto-complete="off" placeholder="id"
                        disabled></el-input>
            </el-form-item>
            <el-form-item label="任务名称">
              <el-input size="small" v-model="editForm.taskName" auto-complete="off" placeholder="任务名称"
              ></el-input>
            </el-form-item>
            <el-form-item label="任务类型">
              <el-select size="small" v-model="editForm.taskType" auto-complete="off" placeholder="任务类型"
              >
                <el-option value="任务" label="任务"></el-option>
                <el-option value="缺陷" label="缺陷"></el-option>
                <el-option value="需求" label="需求"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="任务状态">
              <el-select size="small" v-model="editForm.taskStatus" auto-complete="off" placeholder="任务类型"
              >
                <el-option value="创建" label="创建"></el-option>
                <el-option value="进行中" label="进行中"></el-option>
                <el-option value="完成" label="完成"></el-option>
                <el-option value="废弃" label="废弃"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="所属人">
              <el-select size="small" v-model="editForm.taskOwnerAccount" filterable placeholder="所属人">
                <el-option v-for="(user,index) in orgNumbers" :label="user.account" :value="user.account" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="参与者">
              <el-select size="small" v-model="taskNumbers" multiple filterable placeholder="参与者">
                <el-option v-for="(user,index) in orgNumbers" :label="user.account" :value="user.account" :key="index"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="所属项目">
              <el-select size="small" v-model="editForm.projectName" filterable placeholder="所属项目">
                <el-option v-for="(project, index) in orgProjects" :label="project.projectName"
                           :value="project.projectName"  :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="内容">
              <qiallQuillEditor @handleContext="handleContext" :context="editForm.context"/>
            </el-form-item>
            <el-form-item label="">
              <el-button v-show="editFormVisible_add" @click="submitForm()">添加任务</el-button>
              <el-button v-show="editFormVisible_mod" @click="submitForm()">修改任务</el-button>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {OrderList, OrderRefund, OrderDelete} from '../../api/payMG'
import Pagination from '../../components/Pagination'
import {
  addProjectTask,
  getOrgByPage,
  getProjectByPage,
  getTaskByPage,
  getUserByAccount,
  saveOrUpdateProject
} from "../../api/basisMG";
import {getStore} from "../../utils/util";
import qiallQuillEditor from "../component/qiall-quill-editor";

export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      editFormVisible_add: true,
      editFormVisible_mod: false,
      title: '预览',
      editForm: {
        id: null,
        taskName: '',
        taskType: '',
        taskStatus: '',
        context: '',
        taskOwnerAccount: '',
        orgId: null,
        startTime: '',
        endTime: '',
        progressRate: '',
        projectName: '',
        taskMembers: '',
        accessToken: ''
      },
      orgNumbers: [{
        account: ''
      }],
      orgProjects: [
        {
          projectName: ''
        }
      ],
      taskNumbers: [],
      formInline: {
        pageQuery: {
          startTime: null,
          endTime: null,
          pageSize: 10,
          pageNum: 1
        },
        accessToken: getStore('accessToken'),
        taskDTO: {
          taskType: '',
          taskStatus: ''
        }

      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [
        {
          id: null,
          taskName: '',
          taskType: '',
          taskOwnerId: null,
          taskOwnerName: '',
          context: '',
          creatorId: null,
          creatorName: '',
          taskMemberIds: '',
          taskMemberNames: '',
          orgId: 1,
          orgName: '',
          projectId: null,
          projectMemberIds: '',
          projectName: ''
        }
      ], //项目数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination,
    qiallQuillEditor
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
    // 初始化组内成员
    this.initOrgNumber()

    this.initOrgProject()

  },
  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata() {
      this.loading = true
      this.formInline.pageQuery.pageSize = this.pageparm.pageSize
      this.formInline.pageQuery.pageNum = this.pageparm.currentPage
      // 模拟数据开始
      let requestDataString = {
        requestData: JSON.stringify([this.formInline])
      }

      getTaskByPage(requestDataString).then(resp => {
        if (resp.body.responseData.status === 0) {
          this.loading = false
          this.listData = resp.body.responseData.body.dataList
          this.pageparm.total = resp.body.responseData.body.total
        }
      })
      this.loading = false
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
    },
    handleContext(val){
      this.editForm.context=val;
    },
    initOrgNumber() {
      let queryData = {
        accessToken: getStore('accessToken')
      }
      let requestDataString = {
        requestData: JSON.stringify([queryData])
      }
      let _this = this;
      getUserByAccount(requestDataString).then(resp => {
        if (resp.body.responseData.status === 0) {
          _this.orgNumbers = resp.body.responseData.body
        }
      })
    },
    initOrgProject() {
      let queryData = {
        accessToken: getStore('accessToken')
      }
      let requestDataString = {
        requestData: JSON.stringify([queryData])
      }
      let _this = this;
      getOrgByPage(requestDataString).then(resp => {
        if (resp.body.responseData.status === 0) {
          _this.orgProjects = resp.body.responseData.body
        }
      })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.editFormVisible_add = false
      this.editFormVisible_mod = true
      this.editForm = row
      this.editForm.accessToken = getStore('accessToken')
      console.log(row.taskMembers.split(','))
      this.taskNumbers = row.taskMembers.split(',')

    }
    ,
    //显示编辑界面
    handelAdd: function () {
      this.editFormVisible = true
      this.editFormVisible_add = true
      this.editFormVisible_mod = false
    }
    ,
    // 编辑、增加页面保存方法
    submitForm() {
      if (this.editFormVisible_add == true) {
        this.editForm.id = null;
      }

      this.editForm.taskMembers = this.taskNumbers.join(',')
      let requestDataString = {
        requestData: JSON.stringify([this.editForm])
      }
      addProjectTask(requestDataString)
        .then(res => {
          this.editFormVisible = false
          this.loading = false
          if (res.body.responseData.status === 0) {
            this.getdata()
            this.$message({
              type: 'success',
              message: '新增成功'
            })
          } else {
            this.$message({
              type: 'info',
              message: '新增失败'
            })
          }
        })
        .catch(err => {
          this.editFormVisible = false
          this.loading = false
          this.$message.error('新增项目失败')
        })

    }
    ,
    // 删除公司
    deleteUser(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          ConfigDelete(row.deptId)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '公司已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('支付配置信息删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
    ,
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}

</style>




